#-*- codeing = utf-8 -*-
#@Time: 2020/7/9 22:57
#@Author: YANGYUJIE
#@File: spider_test.py
#@Software: PyCharm
import requests
from lxml import html

def spider(city):
    url = 'https://s.tuniu.com/search_complex/whole-cd-0-{0}'.format(city)
    # 获取html文档
    html_doc = requests.get(url).text
    # print(html_doc)
    # xpath对象
    selector = html.fromstring(html_doc)
    # 解析热门旅游地点
    ul_list = selector.xpath('//*[@id="niuren_list"]/div[2]/div[1]/div[2]/div[1]/div/div[6]/dl/dd/ul/li')
    for li in ul_list:
        hot = li.xpath('a/text()')
        print(hot[0].replace('\n',''))

if __name__ == '__main__':
    city = '成都'
    spider(city)